package com.yanqu.road.server.cmd.activity.langyabang.fromCross;

import com.yanqu.road.entity.union.activitygroup.UnionActivityGroup;
import com.yanqu.road.entity.union.activitygroup.UnionActivityGroupUnion;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.LangYaBangProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.langyabang.LangYaBangMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

@Cmd(code = GameProtocol.S_LANG_YA_BANG_SYNC_NEW_DECLARE_WAR_FROM_CROSS, desc = "新的宣战公告同步")
public class LangYaNewDeclareWarNoticeFromCrossCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        LangYaBangProto.LangYaBangDeclareWarNoticeSyncMsg declareWarNoticeSyncMsg = LangYaBangProto.LangYaBangDeclareWarNoticeSyncMsg.parseFrom(packet.getBytes());
        int groupId = declareWarNoticeSyncMsg.getGroupId();
        int activityId = declareWarNoticeSyncMsg.getActivityId();
        if (LangYaBangMgr.getActivityInfo().getActivityId() != activityId) {
            return;
        }
        List<GamePlayer> allOnlinePlayer = GamePlayerMgr.getAllOnlinePlayer();
        for (GamePlayer onlinePlayer : allOnlinePlayer) {
            int playerGroup = GameUnionActivityGroupMgr.getGroupId(activityId, onlinePlayer.getUserId());
            if (playerGroup == groupId) {
                onlinePlayer.sendPacket(ClientProtocol.U_LANG_YA_BANG_NEW_DECLARE_WAR_SYNC, declareWarNoticeSyncMsg.toBuilder());
            }
        }
    }


    @Override
    public void sendData(GamePlayer player) {

    }
}
